<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>

<h2><?php echo $this->translate("Game Plugin") ?></h2>

<?php if( count($this->navigation) ): ?>
  <div class='tabs'>
    <?php
      // Render the menu
      //->setUlClass()
      echo $this->navigation()->menu()->setContainer($this->navigation)->render()
    ?>
  </div>
<?php endif; ?>

<script type="text/javascript">
  var fetchDistributorType =function(type_id){
    window.location.href= en4.core.baseUrl+'admin/game/distributors/import/type/'+type_id;
    //alert(type_id);
  }
</script>

<?php if (Engine_Api::_()->getApi('settings', 'core')->game_categorymapping === null): ?>
    <div class="tip">
      <span>
        <?php echo $this->translate('Look like "Distributor Category Mapping" settings have not been updated properly. It is very likely due to caching enabled or not cleared while performing the installation. You can fix this by simply switch your site to run on "Development Mode", then back to "Production Mode" located on Admin Dashboard; and/or flush the cache under "Settings :: Performance & Caching" page.') ?>
      </span>
    </div>
<?php endif; ?>

<div class='clear'>
  <div class='settings'>
    <?php echo $this->form->render($this) ?>
  </div>
</div>  
<br />
<br />

<?php if ($this->plugin): ?>
<div class="admin_search">
  <div class="search">
    <?php $feedUrl = $this->plugin->getFeedUrl(); ?>
    <?php echo $this->translate('Game Feed URL: %s', $this->htmlLink($feedUrl, $feedUrl, array('target'=>'_blank')));?>
  </div>
</div>
<?php endif; ?>
<br />
<br />
<div class="games_import">
<?php if ($this->exception instanceof Exception): ?>

    <ul class="form-errors">
      <li><?php echo $this->translate("An error was occured while trying to connect to distributor's host. Please try again later! [Exception: %s]", $this->exception->getMessage()) ?></li>
    </ul>

<?php elseif (is_array($this->games)): ?>

  <script type="text/javascript">
  $('game_import_live_log').hide();
  </script>

  <?php $total_games = count($this->games); ?>
  
  <pre>
  <?php // print_r($this->games);?>
  </pre>
  <?php if ($total_games): ?>
    <?php // echo $this->translate(array('Imported %s game', 'Imported %s games', $total_games), $total_games); ?>
    <table class="admin_table">
      <thead>
        <tr>
          <th><?php echo $this->translate('Distributor Ref ID')?></th>
          <th><?php echo $this->translate('Game Title')?></th>
          <th><?php echo $this->translate('Import Result')?></th>
          <th><?php echo $this->translate('SWF')?></th>
          <th><?php echo $this->translate('Photo')?></th>
          <th><?php echo $this->translate('Data')?></th>
        </tr>
      </thead>
      <tbody>
      <?php foreach ($this->games as $i => $game): ?>
        <tr>
          <td><?php echo $this->htmlLink(array('route'=>'admin_default','module'=>'game','controller'=>'manage','action'=>'index','distributor_ref_id'=>$game['distributor_ref_id']), $game['distributor_ref_id'])?></td>
          <td><?php echo $game['title']?></td>
          <td>
            <?php if (is_int($game['import_result']) && $game['import_result'] == $game['game_id']): ?>
              <?php $game_link = $this->htmlLink(array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'edit', 'game_id' => $game['game_id']), $game['game_id'], array('target'=>'_blank'))?>
              <span class="game_result_pass"><?php echo $this->translate('SUCCESS | ID %s', $game_link)?></span>
            <?php elseif (in_array($game['import_result'], array('already exist', 'category not match', 'category not exist'))): ?>
              <span class="game_result_warn"><?php echo $this->translate($game['import_result'])?></span>
            <?php else: ?>
              <span class="game_result_fail"><?php echo $this->translate('Unknown Error'); ?></span>
            <?php endif; ?>
          </td>
	      <td>
            <?php if (isset($game['import_download_swf'])): ?>
              <?php if ($game['import_download_swf'] === true): ?>
                <span class="game_result_pass"><?php echo $this->translate('OKIE')?></span>
              <?php elseif ($game['import_download_swf'] === false): ?>
                <span class="game_result_warn"><?php echo $this->translate('FAIL')?></span>
              <?php elseif ($game['import_download_swf'] instanceof Exception): ?>
                <span class="game_result_fail"><?php echo $this->translate('ERROR: %s', $game['import_download_swf']->getMessage())?></span>
              <?php endif;?>
            <?php else: ?>
              <span class="game_result_skip"><?php echo $this->translate('SKIP')?></span>
            <?php endif;?>
          </td> 
          <td>
            <?php if (isset($game['import_download_photo'])): ?>
              <?php if ($game['import_download_photo'] === true): ?>
                <span class="game_result_pass"><?php echo $this->translate('OKIE')?></span>
              <?php elseif ($game['import_download_photo'] === false): ?>
                <span class="game_result_warn"><?php echo $this->translate('FAIL')?></span>
              <?php elseif ($game['import_download_photo'] instanceof Exception): ?>
                <span class="game_result_fail"><?php echo $this->translate('ERROR: %s', $game['import_download_photo']->getMessage())?></span>
              <?php endif;?>
            <?php else: ?>
              <span class="game_result_skip"><?php echo $this->translate('SKIP')?></span>
            <?php endif;?>
          </td>   
          <td>
            <a href="javascript: void(0);" onclick="Smoothbox.open($('game_data_<?php echo $i; ?>')); return false;"><?php echo $this->translate('View')?></a>
            <div style="display: none;">
              <div id="game_data_<?php echo $i; ?>" class="game_data_raw"><?php print_r($game); ?></div>
            </div>
          </td>  
        </tr>
      <?php endforeach;?>
      </tbody>
    </table>
  <?php else: ?>
    <?php echo $this->translate('No games found.'); ?>
  <?php endif; ?>
<?php endif; ?>
</div>